<?php

namespace App;

use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Builder;

class Note extends Model
{
    // 手记
    protected $table = "note";
    public $timestamps = false;
    protected $guarded = ['id'];

    protected static function booted()
    {
        static::addGlobalScope('count', function (Builder $builder) {
            $builder->withCount(['like','comment']);
        });
    }

    public function user()
    {
        return $this->belongsTo('App\User');
    }

    public function zone()
    {
        return $this->belongsTo('App\Zone');
    }

    public function comment()
    {
        return $this->hasMany('App\Note_Comment');
    }

    public function like()
    {
        return $this->hasMany('App\Note_like');
    }
}
